namespace Framework
{
    public class Sequence<T> : Composite<T>
    {
        public override TaskStatus Update(T context)
        {
            Behavior<T> child = _children[_currentChildIndex];
            TaskStatus status = child.Tick(context);
            if (status != TaskStatus.Success)
            {
                return status;
            }

            ++_currentChildIndex;
            if (_currentChildIndex == _children.Count)
            {
                _currentChildIndex = 0;
                return TaskStatus.Success;
            }

            return TaskStatus.Running;
        }
    }
}